System.IO.DirectoryInfo di = new DirectoryInfo("YourPath");
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
dir.Delete(true);
}
string rootFolderPath = @"C:\\SomeFolder\\AnotherFolder\\FolderCOntainingThingsToDelete";
string filesToDelete = @"*DeleteMe*.doc"; // Only delete DOC files containing "DeleteMe" in their filenames
string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete);
foreach(string file in fileList)
{
System.Diagnostics.Debug.WriteLine(file + "will be deleted");
// System.IO.File.Delete(file);
}
string gpath;
string path=@"c:\Users\Adam\Desktop\";
string name="file";
string f="";
int i=0;
string ext=".txt";
while(File.Exists(path + name + f + ext))
{
i++;
f = i.ToString();
}
gpath = path + name + f + ext;
button2.Enabled = true;
File.Create(gpath);
File.Delete(gpath);//why there is an Error??